{extend name="public/base" /}

{block name="title"}<title>套餐管理</title>{/block}

{block name="pjax_container"}
<section class="content-header">
    <h1>套餐管理</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="box box-primary">
                <div class="box-header with-border">
                    <div class="pull-left">
                        <a class="btn btn-info btn-sm {if !input('get.status')}active{/if}" href="{:url('index')}"><i class="fa fa-list"></i> 全部</a>
                        <a class="btn btn-info btn-sm {if input('get.status')==1}active{/if}" href="?status=1"><i class="fa fa-gift"></i> 出售中</a>
                        <a class="btn btn-info btn-sm {if input('get.status')==2}active{/if}" href="?status=2"><i class="fa fa-gift"></i> 仓库中</a>
                    </div>
                </div>
                <div class="box-header with-border">
                    {include file="public/top_action" /}
                    {include file="public/search" /}
                </div>
                <div class="box-body table-responsive">
                    <table class="table table-bordered table-hover table-sort">
                        <tr>
                            <th width="35"><input type="checkbox" class="minimal checkbox-toggle"></th>
                            <th>ID{:table_sort('id')}</th>
                            <th>所属分类</th>
                            <th>主图</th>
                            <th>标题</th>
                            <th>原价</th>
                            <th>现价</th>
                            <th>排序{:table_sort('sort')}</th>
                            <th>显示{:table_sort('status')}</th>
                            <th>最新修改时间</th>
                            <th width="124">{$Think.lang.action}</th>
                        </tr>
                        {volist name="dataList" id="vo"}
                        <tr>
                            <td><input type="checkbox" name="id[]" value="{$vo.id}" class="minimal"></td>
                            <td style="vertical-align:middle">{$vo.id}</td>
                            <td style="vertical-align:middle">{$vo.category->catename}</td>
                            <td style="vertical-align:middle"><img src="{$vo.image}" style="width:50px;border-radius:50%;" /></td>
                            <td style="vertical-align:middle"><span class="editable" data-pk="{$vo.id}" data-name="title" data-url="{:url(CONTROLLER_NAME.'/edit', 'id='.$vo['id'])}" >{$vo.title}</span></td>
                            <td style="vertical-align:middle"><span class="editable" data-pk="{$vo.id}" data-name="cost" data-url="{:url(CONTROLLER_NAME.'/edit', 'id='.$vo['id'])}" >{$vo.cost}</span></td>
                            <td style="vertical-align:middle"><span class="editable" data-pk="{$vo.id}" data-name="price" data-url="{:url(CONTROLLER_NAME.'/edit', 'id='.$vo['id'])}" >{$vo.price}</span></td>
                            <td style="vertical-align:middle"><span class="editable" data-pk="{$vo.id}" data-name="sort" data-url="{:url(CONTROLLER_NAME.'/edit', 'id='.$vo['id'])}" >{$vo.sort}</span></td>
                            <td style="vertical-align:middle">
                                <a href="javascript:void(0);" data-id="{$vo.id}" data-field="status" 
                                data-value="{$vo.status}" data-url="{:url('edit', 'id='.$vo['id'])}" 
                                class='editimg fa {if $vo.status == 1 }fa-check-circle text-green{else /}fa-times-circle text-red{/if}'></a>
                            </td>
                            <td style="vertical-align:middle">{$vo.update_time}</td>
                            <td style="vertical-align:middle">{include file="public/list_action" /}</td>
                        </tr>
                        {/volist}
                    </table>
                </div>
                <div class="box-footer clearfix">
                    {$dataList->render()|raw}
                </div>
            </div>
        </div>
    </div>
</section>
<script type="text/javascript">
$(function(){
    /*ajax页面加载icheck，有该控件的页面才需要*/
    $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
        checkboxClass: 'icheckbox_minimal-blue',
        radioClass: 'iradio_minimal-blue'
    });
    
    /*全选-反选*/
    $('.checkbox-toggle').on('ifChecked', function(event){
        var _this = $(this);
        var _table = _this.closest('.table');
        _table.find("tr td input[type='checkbox']").iCheck("check");
    });
    $('.checkbox-toggle').on('ifUnchecked', function(event){
        var _this = $(this);
        var _table = _this.closest('.table');
        _table.find("tr td input[type='checkbox']").iCheck("uncheck");
    });
    
    $('.editable').editable({
        emptytext: "empty",
        params: function(params) {      //参数
            var data = {};
            data['id'] = params.pk;
            data[params.name] = params.value;
            return data;
        },
        success: function(response, newValue) {
            var res = $.parseJSON( response );
            if(res.status == 1){
                toastr.success(res.info);
            }else{
                return res.info;
            }
        }
    });
})
</script>
{/block}